export enum FILTER_PARAMS_ENUM {
  HOME_FILTER_PARAMS_NAME = "sn_home_filter_params",
  CHAIN_B2C_FILTER_PARAMS_NAME = "sn_chain_b2c_filter_params",
  CHAIN_O2O_FILTER_PARAMS_NAME = "sn_chain_o2o_filter_params",
  SPECIAL_FILTER_PARAMS_NAME = "sn_special_filter_params",
  SPECIAL_CODE_PARAMS_NAME = "sn_special_code_filter_params",
  COCKPIT_TYPE_PARAMS_NAME = "sn_cockpit_type_filter_params",
}

export function setSearchParams(key: string, value: any) {
  return localStorage.setItem(key, JSON.stringify(Object.assign({}, value)));
}

export function getSearchParams(key: string) {
  try {
    return localStorage.getItem(key) ? JSON.parse(localStorage.getItem(key) as string) : "";
  } catch (error) {
    return localStorage.getItem(key);
  }
}

export function clearSearchParams(key: string) {
  return localStorage.getItem(key) && localStorage.removeItem(key);
}

export function clearAllSearchParams() {
  Object.keys(FILTER_PARAMS_ENUM).forEach((item: any) => {
    clearSearchParams(item);
  });
}

export function clearSomeSearchParams(someEnum: string[]) {
  someEnum.forEach((item: any) => {
    clearSearchParams(item);
  });
}
